using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.Collections;

namespace SWAS.Web.UI.Controls
{
    [Serializable]
    public class SelectedValue
    {
        private List<string> values;
        private List<string> keys;

        public SelectedValue(DataKey dataKey)
        {
            values = new List<string>();
            keys = new List<string>();
            IDictionaryEnumerator enu = dataKey.Values.GetEnumerator();
            while (enu.MoveNext())
            {
                values.Add(enu.Value.ToString());
                keys.Add(enu.Key.ToString());
            }
        }

        public string this[int index]
        {
            get { return values[index]; }
        }

        public string this[string key]
        {
            get { return values[keys.IndexOf(key)]; }
        }

        public override bool Equals(object obj)
        {
            if (obj is SelectedValue)
            {
                SelectedValue s = (SelectedValue)obj;
                if (s.keys.Count == this.keys.Count)
                {
                    for (int i = 0; i < s.keys.Count; i++)
                    {
                        if (s.keys[i] != this.keys[i])
                        {
                            return false;
                        }
                        if (s.values[i] != this.values[i])
                        {
                            return false;
                        }
                    }
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

    }
}
